package com.esri.core.geometry;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* loaded from: classes.dex */
class OperatorExportToESRIShapeCursor extends ByteBufferCursor {
    GeometryCursor a;
    int b;
    int c = -1;
    ByteBuffer d;

    public OperatorExportToESRIShapeCursor(int i, GeometryCursor geometryCursor) {
        if (geometryCursor == null) {
            throw new GeometryException("invalid argument");
        }
        this.b = i;
        this.a = geometryCursor;
        this.d = null;
    }

    @Override // com.esri.core.geometry.ByteBufferCursor
    public int getByteBufferID() {
        return this.c;
    }

    @Override // com.esri.core.geometry.ByteBufferCursor
    public ByteBuffer next() {
        Geometry next = this.a.next();
        if (next != null) {
            this.c = this.a.getGeometryID();
            int a = a(this.b, next, (ByteBuffer) null);
            ByteBuffer byteBuffer = this.d;
            if (byteBuffer == null || a > byteBuffer.capacity()) {
                this.d = ByteBuffer.allocate(a).order(ByteOrder.LITTLE_ENDIAN);
            }
            a(this.b, next, this.d);
            return this.d;
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static int a(int i, Geometry geometry, ByteBuffer byteBuffer) {
        if (geometry == null) {
            if (byteBuffer != null) {
                byteBuffer.putInt(0, 0);
                return 4;
            }
            return 4;
        }
        int value = geometry.getType().value();
        if (value != 513) {
            if (value != 3077) {
                if (value != 8710) {
                    if (value != 25607) {
                        if (value == 27656) {
                            return a(true, i, (MultiPath) geometry, byteBuffer);
                        }
                        throw new GeometryException("internal error");
                    }
                    return a(false, i, (MultiPath) geometry, byteBuffer);
                }
                return a(i, (MultiPoint) geometry, byteBuffer);
            }
            return a(i, (Envelope) geometry, byteBuffer);
        }
        return a(i, (Point) geometry, byteBuffer);
    }

    private static int a(int i, Envelope envelope, ByteBuffer byteBuffer) {
        boolean z = envelope.e(1) && (i & 16) == 0;
        boolean z2 = envelope.e(2) && (i & 32) == 0;
        boolean z3 = envelope.e(3) && (i & 64) == 0;
        boolean z4 = (i & 8) == 0;
        boolean isEmpty = envelope.isEmpty();
        int i2 = !isEmpty;
        int i3 = isEmpty != 0 ? 0 : 5;
        int i4 = 44;
        int i5 = (i2 * 4) + 44 + (i3 * 2 * 8);
        if (z) {
            i5 += (i3 * 8) + 16;
        }
        if (z2) {
            i5 += (i3 * 8) + 16;
        }
        if (z3) {
            i5 += i3 * 4;
        }
        if (byteBuffer == null) {
            return i5;
        }
        if (byteBuffer.capacity() < i5) {
            throw new GeometryException("buffer is too small");
        }
        byteBuffer.putInt(0, (z || z2) ? (!z || z2) ? (!z2 || z) ? z3 ? -805306317 : 15 : z3 ? 1342177331 : 25 : z3 ? -1879048141 : 19 : z3 ? 268435507 : 5);
        Envelope2D envelope2D = new Envelope2D();
        envelope.queryEnvelope2D(envelope2D);
        boolean z5 = z3;
        byteBuffer.putDouble(4, envelope2D.xmin);
        boolean z6 = z2;
        byteBuffer.putDouble(12, envelope2D.ymin);
        byteBuffer.putDouble(20, envelope2D.xmax);
        byteBuffer.putDouble(28, envelope2D.ymax);
        byteBuffer.putInt(36, i2);
        byteBuffer.putInt(40, i3);
        if (isEmpty == 0) {
            byteBuffer.putInt(44, 0);
            byteBuffer.putDouble(48, envelope2D.xmin);
            byteBuffer.putDouble(56, envelope2D.ymin);
            byteBuffer.putDouble(64, envelope2D.xmin);
            byteBuffer.putDouble(72, envelope2D.ymax);
            byteBuffer.putDouble(80, envelope2D.xmax);
            byteBuffer.putDouble(88, envelope2D.ymax);
            byteBuffer.putDouble(96, envelope2D.xmax);
            byteBuffer.putDouble(104, envelope2D.ymin);
            byteBuffer.putDouble(112, envelope2D.xmin);
            byteBuffer.putDouble(120, envelope2D.ymin);
            i4 = 128;
        }
        if (z) {
            Envelope1D queryInterval = envelope.queryInterval(1, 0);
            double d = queryInterval.vmin;
            if (z4) {
                d = Interop.translateToAVNaN(d);
            }
            double d2 = queryInterval.vmax;
            if (z4) {
                d2 = Interop.translateToAVNaN(d2);
            }
            byteBuffer.putDouble(i4, d);
            int i6 = i4 + 8;
            byteBuffer.putDouble(i6, d2);
            i4 = i6 + 8;
            if (isEmpty == 0) {
                byteBuffer.putDouble(i4, d);
                int i7 = i4 + 8;
                byteBuffer.putDouble(i7, d2);
                int i8 = i7 + 8;
                byteBuffer.putDouble(i8, d);
                int i9 = i8 + 8;
                byteBuffer.putDouble(i9, d2);
                int i10 = i9 + 8;
                byteBuffer.putDouble(i10, d);
                i4 = i10 + 8;
            }
        }
        if (z6) {
            Envelope1D queryInterval2 = envelope.queryInterval(2, 0);
            double d3 = queryInterval2.vmin;
            if (z4) {
                d3 = Interop.translateToAVNaN(d3);
            }
            double d4 = queryInterval2.vmax;
            if (z4) {
                d4 = Interop.translateToAVNaN(d4);
            }
            byteBuffer.putDouble(i4, d3);
            int i11 = i4 + 8;
            byteBuffer.putDouble(i11, d4);
            i4 = i11 + 8;
            if (isEmpty == 0) {
                byteBuffer.putDouble(i4, d3);
                int i12 = i4 + 8;
                byteBuffer.putDouble(i12, d4);
                int i13 = i12 + 8;
                byteBuffer.putDouble(i13, d3);
                int i14 = i13 + 8;
                byteBuffer.putDouble(i14, d4);
                int i15 = i14 + 8;
                byteBuffer.putDouble(i15, d3);
                i4 = i15 + 8;
            }
        }
        if (z5 && isEmpty == 0) {
            Envelope1D queryInterval3 = envelope.queryInterval(3, 0);
            int i16 = (int) queryInterval3.vmin;
            int i17 = (int) queryInterval3.vmax;
            byteBuffer.putInt(i4, i16);
            int i18 = i4 + 4;
            byteBuffer.putInt(i18, i17);
            int i19 = i18 + 4;
            byteBuffer.putInt(i19, i16);
            int i20 = i19 + 4;
            byteBuffer.putInt(i20, i17);
            int i21 = i20 + 4;
            byteBuffer.putInt(i21, i16);
            return i21 + 4;
        }
        return i4;
    }

    private static int a(int i, Point point, ByteBuffer byteBuffer) {
        int i2 = 1;
        boolean z = point.e(1) && (i & 16) == 0;
        boolean z2 = point.e(2) && (i & 32) == 0;
        boolean z3 = point.e(3) && (i & 64) == 0;
        boolean z4 = (i & 8) == 0;
        int i3 = 28;
        int i4 = z ? 28 : 20;
        if (z2) {
            i4 += 8;
        }
        if (z3) {
            i4 += 4;
        }
        if (byteBuffer == null) {
            return i4;
        }
        if (byteBuffer.capacity() < i4) {
            throw new GeometryException("buffer is too small");
        }
        if (z || z2) {
            i2 = (!z || z2) ? (!z2 || z) ? z3 ? -805306316 : 11 : z3 ? 1342177332 : 21 : z3 ? -1879048140 : 9;
        } else if (z3) {
            i2 = 268435508;
        }
        byteBuffer.putInt(0, i2);
        boolean isEmpty = point.isEmpty();
        double x = !isEmpty ? point.getX() : NumberUtils.NaN();
        double y = !isEmpty ? point.getY() : NumberUtils.NaN();
        if (z4) {
            x = Interop.translateToAVNaN(x);
        }
        byteBuffer.putDouble(4, x);
        if (z4) {
            y = Interop.translateToAVNaN(y);
        }
        byteBuffer.putDouble(12, y);
        if (z) {
            double z5 = !isEmpty ? point.getZ() : NumberUtils.NaN();
            if (z4) {
                z5 = Interop.translateToAVNaN(z5);
            }
            byteBuffer.putDouble(20, z5);
        } else {
            i3 = 20;
        }
        if (z2) {
            double m = !isEmpty ? point.getM() : NumberUtils.NaN();
            if (z4) {
                m = Interop.translateToAVNaN(m);
            }
            byteBuffer.putDouble(i3, m);
            i3 += 8;
        }
        if (z3) {
            byteBuffer.putInt(i3, isEmpty ? 0 : point.j());
            return i3 + 4;
        }
        return i3;
    }

    private static int a(int i, MultiPoint multiPoint, ByteBuffer byteBuffer) {
        boolean z;
        int i2;
        MultiPointImpl multiPointImpl = (MultiPointImpl) multiPoint._getImpl();
        int i3 = 1;
        int i4 = 0;
        boolean z2 = multiPointImpl.e(1) && (i & 16) == 0;
        boolean z3 = multiPointImpl.e(2) && (i & 32) == 0;
        boolean z4 = multiPointImpl.e(3) && (i & 64) == 0;
        boolean z5 = (i & 8) == 0;
        int pointCount = multiPointImpl.getPointCount();
        int i5 = (pointCount * 2 * 8) + 40;
        if (z2) {
            i5 += (pointCount * 8) + 16;
        }
        if (z3) {
            i5 += (pointCount * 8) + 16;
        }
        if (z4) {
            i5 += pointCount * 4;
        }
        if (i5 < NumberUtils.intMax()) {
            if (byteBuffer == null) {
                return i5;
            }
            if (byteBuffer.capacity() < i5) {
                throw new GeometryException("buffer is too small");
            }
            byteBuffer.putInt(0, (z2 || z3) ? (!z2 || z3) ? (!z3 || z2) ? z4 ? -805306315 : 18 : z4 ? 1342177333 : 28 : z4 ? -1879048139 : 20 : z4 ? 268435509 : 8);
            Envelope2D envelope2D = new Envelope2D();
            multiPointImpl.queryEnvelope2D(envelope2D);
            boolean z6 = z4;
            byteBuffer.putDouble(4, envelope2D.xmin);
            boolean z7 = z3;
            byteBuffer.putDouble(12, envelope2D.ymin);
            byteBuffer.putDouble(20, envelope2D.xmax);
            byteBuffer.putDouble(28, envelope2D.ymax);
            byteBuffer.putInt(36, pointCount);
            if (pointCount > 0) {
                AttributeStreamOfDbl attributeStreamOfDbl = (AttributeStreamOfDbl) multiPointImpl.getAttributeStreamRef(0);
                i2 = 40;
                int i6 = 0;
                while (i6 < pointCount) {
                    int i7 = i6 * 2;
                    double read = attributeStreamOfDbl.read(i7);
                    double read2 = attributeStreamOfDbl.read(i7 + i3);
                    byteBuffer.putDouble(i2, read);
                    int i8 = i2 + 8;
                    byteBuffer.putDouble(i8, read2);
                    i2 = i8 + 8;
                    i6++;
                    z2 = z2;
                    i3 = 1;
                }
                z = z2;
            } else {
                z = z2;
                i2 = 40;
            }
            if (z) {
                Envelope1D queryInterval = multiPointImpl.queryInterval(1, 0);
                double d = queryInterval.vmin;
                if (z5) {
                    d = Interop.translateToAVNaN(d);
                }
                byteBuffer.putDouble(i2, d);
                int i9 = i2 + 8;
                double d2 = queryInterval.vmax;
                if (z5) {
                    d2 = Interop.translateToAVNaN(d2);
                }
                byteBuffer.putDouble(i9, d2);
                i2 = i9 + 8;
                if (pointCount > 0) {
                    if (multiPointImpl._attributeStreamIsAllocated(1)) {
                        AttributeStreamOfDbl attributeStreamOfDbl2 = (AttributeStreamOfDbl) multiPointImpl.getAttributeStreamRef(1);
                        for (int i10 = 0; i10 < pointCount; i10++) {
                            double read3 = attributeStreamOfDbl2.read(i10);
                            if (z5) {
                                read3 = Interop.translateToAVNaN(read3);
                            }
                            byteBuffer.putDouble(i2, read3);
                            i2 += 8;
                        }
                    } else {
                        double defaultValue = VertexDescription.getDefaultValue(1);
                        if (z5) {
                            defaultValue = Interop.translateToAVNaN(defaultValue);
                        }
                        for (int i11 = 0; i11 < pointCount; i11++) {
                            byteBuffer.putDouble(i2, defaultValue);
                        }
                        i2 += 8;
                    }
                }
            }
            if (z7) {
                Envelope1D queryInterval2 = multiPointImpl.queryInterval(2, 0);
                double d3 = queryInterval2.vmin;
                if (z5) {
                    d3 = Interop.translateToAVNaN(d3);
                }
                byteBuffer.putDouble(i2, d3);
                int i12 = i2 + 8;
                double d4 = queryInterval2.vmax;
                if (z5) {
                    d4 = Interop.translateToAVNaN(d4);
                }
                byteBuffer.putDouble(i12, d4);
                i2 = i12 + 8;
                if (pointCount > 0) {
                    if (multiPointImpl._attributeStreamIsAllocated(2)) {
                        AttributeStreamOfDbl attributeStreamOfDbl3 = (AttributeStreamOfDbl) multiPointImpl.getAttributeStreamRef(2);
                        for (int i13 = 0; i13 < pointCount; i13++) {
                            double read4 = attributeStreamOfDbl3.read(i13);
                            if (z5) {
                                read4 = Interop.translateToAVNaN(read4);
                            }
                            byteBuffer.putDouble(i2, read4);
                            i2 += 8;
                        }
                    } else {
                        double defaultValue2 = VertexDescription.getDefaultValue(2);
                        if (z5) {
                            defaultValue2 = Interop.translateToAVNaN(defaultValue2);
                        }
                        for (int i14 = 0; i14 < pointCount; i14++) {
                            byteBuffer.putDouble(i2, defaultValue2);
                        }
                        i2 += 8;
                    }
                }
            }
            if (!z6 || pointCount <= 0) {
                return i2;
            }
            if (multiPointImpl._attributeStreamIsAllocated(3)) {
                AttributeStreamOfInt32 attributeStreamOfInt32 = (AttributeStreamOfInt32) multiPointImpl.getAttributeStreamRef(3);
                while (i4 < pointCount) {
                    byteBuffer.putInt(i2, attributeStreamOfInt32.read(i4));
                    i2 += 4;
                    i4++;
                }
                return i2;
            }
            int defaultValue3 = (int) VertexDescription.getDefaultValue(3);
            while (i4 < pointCount) {
                byteBuffer.putInt(i2, defaultValue3);
                i4++;
            }
            return i2 + 4;
        }
        throw new GeometryException("invalid call");
    }

    /* JADX WARN: Code restructure failed: missing block: B:111:0x011a, code lost:
        if (r9 != false) goto L189;
     */
    /* JADX WARN: Code restructure failed: missing block: B:61:0x00aa, code lost:
        if (r9 != false) goto L189;
     */
    /* JADX WARN: Code restructure failed: missing block: B:62:0x00ac, code lost:
        r9 = r15 | com.esri.core.geometry.ShapeModifiers.ShapeHasCurves;
     */
    /* JADX WARN: Code restructure failed: missing block: B:63:0x00b0, code lost:
        r9 = r15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:79:0x00d6, code lost:
        if (r9 != false) goto L189;
     */
    /* JADX WARN: Code restructure failed: missing block: B:96:0x00fa, code lost:
        if (r9 != false) goto L189;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private static int a(boolean r20, int r21, com.esri.core.geometry.MultiPath r22, java.nio.ByteBuffer r23) {
        /*
            Method dump skipped, instructions count: 814
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.core.geometry.OperatorExportToESRIShapeCursor.a(boolean, int, com.esri.core.geometry.MultiPath, java.nio.ByteBuffer):int");
    }
}
